class PropLogic {

    public static useProp(proptype: number, location: number) {
        switch (proptype) {
            case 0: PropLogic.tongse(location); break;
            case 1: PropLogic.zhadan(location); break;
            case 2: PropLogic.zhenghang(location); break;
            case 3: PropLogic.zhenglie(location); break;
            case 4: PropLogic.chanzi(location); break;
            default: break;
        }
    }

    private static tongse(location: number) {
        let row: number = Math.floor(location / GameData.MaxRow);
        let col: number = location % GameData.MaxColumn;
        let type: string = GameData.elements[GameData.mapData[row][col]].type;

        LinkLogic.lines = [];
        let arr: number[] = [];
        for (let i = 0; i < GameData.MaxRow; i++) {
            for (let j = 0; j < GameData.MaxColumn; j++) {
                if (GameData.mapData[i][j] != -1 && type == GameData.elements[GameData.mapData[i][j]].type) {
                    arr.push(GameData.elements[GameData.mapData[i][j]].id);
                }
            }
        }
        LinkLogic.lines.push(arr);
    }

    private static zhadan(location: number) {
        let row: number = Math.floor(location / GameData.MaxRow);
        let col: number = location % GameData.MaxColumn;

        LinkLogic.lines = [];
        let arr: number[] = [];
        arr.push(GameData.elements[GameData.mapData[row][col]].id)
        if (row > 0 && GameData.mapData[row - 1][col]) { // 上
            arr.push(GameData.elements[GameData.mapData[row - 1][col]].id)
        }
        if (row < GameData.MaxRow - 1 && GameData.mapData[row + 1][col]) { // 下
            arr.push(GameData.elements[GameData.mapData[row + 1][col]].id)
        }
        if (col > 0 && GameData.mapData[row][col - 1]) { // 左
            arr.push(GameData.elements[GameData.mapData[row][col - 1]].id)
        }
        if (col < GameData.MaxColumn - 1 && GameData.mapData[row][col + 1]) { // 右
            arr.push(GameData.elements[GameData.mapData[row][col + 1]].id)
        }
        LinkLogic.lines.push(arr);
    }

    private static zhenghang(location: number) {
        let row: number = Math.floor(location / GameData.MaxRow);

        LinkLogic.lines = [];
        let arr: number[] = [];
        for (let i = 0; i < GameData.MaxColumn; i++) {
            if (GameData.mapData[row][i] != -1) {
                arr.push(GameData.elements[GameData.mapData[row][i]].id);
            }
        }
        LinkLogic.lines.push(arr);
    }

    private static zhenglie(location: number) {
        let col: number = location % GameData.MaxColumn;

        LinkLogic.lines = [];
        let arr: number[] = [];
        for (let i = 0; i < GameData.MaxRow; i++) {
            if (GameData.mapData[i][col] != -1) {
                arr.push(GameData.elements[GameData.mapData[i][col]].id);
            }
        }
        LinkLogic.lines.push(arr);
    }

    private static chanzi(location: number) {
        let row: number = Math.floor(location / GameData.MaxRow);
        let col: number = location % GameData.MaxColumn;

        LinkLogic.lines = [];
        LinkLogic.lines.push([GameData.elements[GameData.mapData[row][col]].id]);
    }
}